import 'package:core_package/ui/widget/my_asset_image.dart';
import 'package:flutter/material.dart';
import 'package:core_package/core_package.dart';
import 'package:flutter_app_unionad/model/recharge_order_model.dart';

class ExchangeItemWidget extends StatelessWidget {
  final bool isRecharge;
  final RechargeOrderModel? model;

  const ExchangeItemWidget({Key? key, this.isRecharge = true, this.model}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    String day;
    // bool userType = (model.userType == '03' || model.userType == '04');
    // if (userType) {
    //   day = isRecharge ? "充值流量" : '兑现流量';
    // } else {}
    day = isRecharge ? "充值天数" : '兑现天数';

    return Container(
        margin: EdgeInsets.only(bottom: 10.px),
        decoration: BoxDecoration(
          color: Colors.white,
          borderRadius: BorderRadius.circular(5.px),
        ),
        padding: EdgeInsets.only(
          left: 37.px,
          right: 20.px,
          top: 20.px,
          bottom: 20.px,
        ),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            builtItem(
              image: "icon_order_1",
              imageSize: Size(8, 12),
              title: "设备编号",
              detail: model!.devId ?? "",
            ),
            MySizeBox(height: 5),
            builtItem(
              image: "icon_order_2",
              imageSize: Size(12, 12),
              title: day,
              detail: '${model!.days == null ? 0 : (model!.days! + (model!.giftDays == null ? 0 : model!.giftDays!))}天',
            ),
            MySizeBox(height: 5),
            builtItem(
              image: "icon_order_3",
              imageSize: Size(10, 13),
              title: isRecharge ? "充值金额" : "兑现金额",
              detail: '${model!.amount.toString()}元',
            ),
            MySizeBox(height: 5),
            builtItem(
              image: "icon_order_4",
              imageSize: Size(12, 12),
              title: isRecharge ? "充值时间" : "兑现时间",
              detail: model!.createDateTime,
            ),
            // if(isRecharge)
            //   builtItem(
            //     image: "icon_order_4",
            //     imageSize: Size(12, 12),
            //     title: '服务时间',
            //     detail: model!.serviceDate,
            //   ),
            //   if(isRecharge)
            //     MySizeBox(height: 5),

            MySizeBox(height: 5),
            builtItem(
              image: "icon_order_5",
              imageSize: Size(12, 12),
              title: "类型",
              detail: isRecharge ? "设备充值" : "兑现",
              detailColor: MyColors.formHex("#4FD8FFFF"),
            ),
            if (model!.serviceDate != null) MySizeBox(height: 5),

            // if (model!.serviceDate !=null && model!.serviceDate != '')
            if (model!.serviceDate != null)
              builtItem(
                image: "icon_order_2",
                imageSize: Size(12, 12),
                title: '服务日期',
                detail: model!.serviceDate ?? '',
              ),
          ],
        ));
  }

  Widget builtItem({
    String? image,
    String? title,
    Size? imageSize,
    String? detail,
    Color? detailColor,
  }) {
    return Row(
      mainAxisSize: MainAxisSize.min,
      children: [
        Container(
          width: 13.px,
          alignment: Alignment.center,
          child: MyAssetImage(
            image ?? '',
            width: imageSize!.width.px,
            height: imageSize.height.px,
            fit: BoxFit.fill,
          ),
        ),
        MySizeBox(width: 15),
        Text(
          "$title：",
          style: TextStyle(
            color: MyColors.formHex("#1D242CFF"),
            fontSize: MyFont.font13,
            fontWeight: MyFontWeight.regular,
          ),
        ),
        Text(
          detail ?? '',
          style: TextStyle(
            decoration: detailColor != null ? TextDecoration.underline : TextDecoration.none,
            color: detailColor ?? MyColors.formHex("#1D242CFF"),
            fontSize: MyFont.font13,
            fontWeight: MyFontWeight.regular,
          ),
        )
      ],
    );
  }
}
